﻿#ifndef __LOG_H___
#define __LOG_H___

#ifdef __cplusplus
extern "C" {
#endif
#include "AvType.h"
	typedef	void(*onDevLog)(LogItem* logItem);

	typedef struct {
		int bPrintLevel;
		int bPrintFileNameLine;
		time_t VaildMinUTC;//无效时间默认2020-01-01 00:00:00 小于这个时间认为无效协议会自动补偿时间
		onDevLog LogProc;
	}LogProfile;


	int			_logInit();
	int			_logSetProfile(LogProfile* Profile);
	LogProfile* _logGetProfile();


	void _DLogMsg(char* File, int Line, const char* fmt, ...);
	void _DLogErr(char* File, int Line, const char* fmt, ...);
	void _DLogWarn(char* File, int Line, const char* fmt, ...);
	void _DLogHint(char* File, int Line, const char* fmt, ...);

#if defined(WIN32)
#	ifndef PATH_HR
#	define PATH_HR '\\'
#	endif
#else // defined(WIN32)
#	ifndef PATH_HR
#	define PATH_HR '/'
#	endif
#endif // defined(WIN32)
#define __FILE_NAME_ (NULL == strrchr(__FILE__, PATH_HR)? (char *)__FILE__:(char *)(strrchr(__FILE__, PATH_HR) + 1))

#if 1
#define _logMsg(fmt,...) _DLogMsg(__FILE_NAME_, __LINE__, fmt, ##__VA_ARGS__)
#define _logWarn(fmt,...) _DLogWarn(__FILE_NAME_, __LINE__, fmt, ##__VA_ARGS__)
#define _logErr(fmt,...) _DLogErr(__FILE_NAME_, __LINE__, fmt, ##__VA_ARGS__)
#define _logHint(fmt,...) _DLogHint(__FILE_NAME_, __LINE__, fmt, ##__VA_ARGS__)
#else
#define _logMsg(fmt,...) printf("\033[1;32m%s:%04d]]" fmt "\033[m",__FILE_NAME_, __LINE__, ##__VA_ARGS__)
#define _logWarn(fmt,...) printf("\033[1;33m%s:%04d]]" fmt "\033[m",__FILE_NAME_, __LINE__, ##__VA_ARGS__)
#define _logErr(fmt,...) printf("\033[0;31m%s:%04d]]" fmt "\033[m",__FILE_NAME_, __LINE__, ##__VA_ARGS__)
#define _logHint(fmt,...) printf("\033[0;31m%s:%04d]]" fmt "\033[m",__FILE_NAME_, __LINE__, ##__VA_ARGS__)
#endif

#ifdef __cplusplus
}
#endif
#endif
